package com.flash.GlobalManagement.controller;

import com.flash.GlobalManagement.entity.Menu;
import com.flash.GlobalManagement.service.LoginService;
import com.flash.demo.service.UserDemoService;
import org.apache.tomcat.util.net.jsse.JSSEUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class LoginUserController {
    @Resource
    LoginService loginService;

    @RequestMapping("/loginUser")
    @ResponseBody
    public Map<String,Object> loginUser(String userName, String userPas, HttpServletRequest request){
        Map<String,Object> map = new HashMap<String, Object>();
        System.out.println("这是动态加载");
        int i = loginService.login(userName, userPas);
        HttpSession session = request.getSession();
        session.setAttribute("userName",userName);
        if (i==1) {
            map.put("code",1);
        }else {
            map.put("code",0);
        }
        return map;
    }

    @RequestMapping("")
    public String toSystem(HttpSession session, Model model){
        System.out.println("这是权限加载");
        return "index";
    }

    @RequestMapping("/users")
    @ResponseBody
    public Map UserFather(){
        //父模块

        Map<String,Object> map = new HashMap<String, Object>();

        List<Menu> menuList = loginService.loadLogin();

        map.put("code",0);
        map.put("msg","");
        map.put("count",null);
        map.put("data",menuList);
        return map;
    }
}
